<?php
include "../../shared/config.php";
include "../../shared/baidu_transapi.php";
include "../../shared/lan.php";

$cv_name = $_POST['cv_name'];
$sex = $_POST['sex'];
$name =$_POST['name'];
$tel = $_POST['tel'];
$email = $_POST['email'];
$education = $_POST['education'];
$certification = $_POST['certification'];
$job = $_POST['job'];
$about = $_POST['about'];
$un = $_GET['name'];
$lang = $_SESSION["language"];
if($lang == "zh"){
	$sql = "INSERT INTO cv (cv_name, sex, name, tel, email, education, certification, job, about,user_name, lan) VALUES ('$cv_name', '$sex', '$name', '$tel', '$email', '$education', '$certification', '$job', '$about','$un','$lang')";
	$from = "zh";
	$to = "en";
}
else{
	$sql = "INSERT INTO cv_en (cv_name, sex, name, tel, email, education, certification, job, about,user_name, lan) VALUES ('$cv_name', '$sex', '$name', '$tel', '$email', '$education', '$certification', '$job', '$about','$un','$lang')";
	$from = "en";
	$to = "zh";
}

$insert = mysqli_query($conn,$sql);

//自动翻译简历功能

$info_array = [$cv_name,$sex,$name,$education,$certification,$job,$about];
$new_array = [];

foreach($info_array as $word){
	$answer = translate($word,$from,$to);
	//echo $answer['trans_result'][0]['dst'];
	sleep(1);
	array_push($new_array,$answer['trans_result'][0]['dst']);
	
}

if($lang == "zh"){
	$sql = "INSERT INTO cv_en (cv_name, sex, name, tel, email, education, certification, job, about,user_name,lan) VALUES ('$new_array[0]', '$new_array[1]', '$new_array[2]', '$tel', '$email', '$new_array[3]', '$new_array[4]', '$new_array[5]', '$new_array[6]','$un','en')";
}
else{
	$sql = "INSERT INTO cv (cv_name, sex, name, tel, email, education, certification, job, about,user_name,lan) VALUES ('$new_array[0]', '$new_array[1]', '$new_array[2]', '$tel', '$email', '$new_array[3]', '$new_array[4]', '$new_array[5]', '$new_array[6]','$un','zh')";
}
echo $sql;
$insert = mysqli_query($conn,$sql);

if(!$insert)
    {  
        echo "无法新增术语信息: ".mysqli_error($conn);  
    }  
    else  
    {  
		//header("location: ../../page/em/index.php");
    }  

mysqli_close($conn);
?>